package com.oceansoft.mobile.econsole.modules.api.controller;

import com.oceansoft.mobile.econsole.modules.api.service.IMediaService;
import com.oceansoft.mobile.econsole.modules.base.controller.BaseController;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * ClassName: ApiMediaController
 * Desc: 视频控制器
 * Date： 2016/12/19
 * Created：shaom
 */
@Controller
@RequestMapping("api/media")
public class ApiMediaController extends BaseController {

    private static final Logger logger = Logger.getLogger(ApiMediaController.class);

    @Resource
    private IMediaService mediaService;


    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index(ModelMap modelMap) {
        Result result = null;
        try {
            result = mediaService.getOrgInfo();
        } catch (IOException e) {
            logger.info("获取设备信息失败!!");
        }
        modelMap.addAttribute("result", result);
        return "weixin/weixinquery/mediaIndex";
    }

    /**
     * 获取设备信息
     *
     * @return
     */
    @RequestMapping("getOrgInfo")
    @ResponseBody
    public Result getOrgInfo() {
        Result result;
        try {
            result = mediaService.getOrgInfo();
        } catch (IOException e) {
            logger.info("获取设备信息失败!!");
            return new Result(Result.FAILURE, "获取设备信息失败!!");
        }
        return result;
    }

    /**
     * 获取视频截图
     *
     * @param id
     * @return
     */
    @RequestMapping("ajax/getVideoImg")
    @ResponseBody
    public Result getVideoImg(String id) {
        Result result;
        try {
            result = mediaService.getVideoImg(id);
        } catch (IOException e) {
            logger.info("获取视频截图失败!!");
            return new Result(Result.FAILURE, "获取视频截图失败!!");
        }
        return result;
    }


}
